package com.yunshang.shoppingmall.controller.Finace;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunshang.shoppingmall.common.LayUIUtil;
import com.yunshang.shoppingmall.entity.ProductClassfy;
import com.yunshang.shoppingmall.entity.UserWtihdrawals;
import com.yunshang.shoppingmall.entity.Withdrawals;
import com.yunshang.shoppingmall.service.UserWtihdrawalsService;
import com.yunshang.shoppingmall.service.WithdrawalsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class WithdrawalsController {

    @Autowired
    WithdrawalsService withdrawalsService;
    @Autowired
    UserWtihdrawalsService userWtihdrawalsService;

    //打开提现申请列表
    @RequestMapping("/openWithdrawals")
    public ModelAndView openWithdrawals() {
        ModelAndView modelAndView = new ModelAndView("Finace/withdrawalsApply");
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping("/getWithdrawalsList")
    public LayUIUtil getWithdrawalsList(HttpServletRequest request) {
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        int pages = 0;
        int limits = 10;
        if (page != null && page != "") {
            pages = Integer.parseInt(page);
        }
        if (limit != null && limit != "") {
            Integer.parseInt(page);
        }
        String tixianSign="1";
        List<UserWtihdrawals> userWtihdrawalsList = userWtihdrawalsService.selectUserWithdrawalsList(tixianSign);
        PageInfo pageInfo = new PageInfo(userWtihdrawalsList);
        int count = 10;
        count = pageInfo.getPages();
        return LayUIUtil.data(count, userWtihdrawalsList);
    }

    @ResponseBody
    @RequestMapping(value = "/updateWithDrawals", method = RequestMethod.POST)
    public Map<String, Object> updateWithDrawals(@RequestParam Map<String, String> withDrawalsMap,HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        int adminId1=(int) request.getSession().getAttribute("adminId");


        int id=0;
        Timestamp timestamp=new Timestamp(System.currentTimeMillis());
        Withdrawals withdrawals=new Withdrawals();
        if(withDrawalsMap!=null){
            id=Integer.parseInt(withDrawalsMap.get("id"));
        }
        withdrawals.setId(id);
        withdrawals.setTixianSign(withDrawalsMap.get("tixianSign"));
        withdrawals.setOpTime(timestamp);
        withdrawals.setOpratorId(adminId1);
        int row=withdrawalsService.updateByPrimaryKeySelective(withdrawals);
        if(row>0){
            map.put("msg","1");
        }
        return  map;
    }


}
